// pages/showIndex/zhinanDetail/zhinanDetail.js
var zhinan_data = require('../../../data/zhinanData.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var postId = options.id;
    this.data.postssId = postId;
    this.setData({
      textData: zhinan_data.zhinanList[postId]
    });

    var postsConllected = wx.getStorageSync('postsConllected');

    if (postsConllected) {
      var conllected = postsConllected[postId];
      this.setData({
        conllected: conllected,
      })
    } else {
      var postsConllected = {}
      postsConllected[postId] = 'false'
      wx.setStorageSync('postsConllected', postsConllected);
    }
  },

  onCollectionTap: function (event) {

    var postsConllected = wx.getStorageSync('postsConllected');

    var postconllected = postsConllected[this.data.postssId];
    postconllected = !postconllected;
    postsConllected[this.data.postssId] = postconllected;
    wx.setStorageSync('postsConllected', postsConllected);
    this.setData({
      conllected: postconllected,
    });

    wx.showToast({
      title: postconllected ? '收藏成功' : '取消成功',
      duration: 1000,
    })

  },

  onShareTap: function (event) {

    var itemList = [
      "分享给微信好友",
      "分享到朋友圈",
      "分享给QQ",
    ];
    wx.showActionSheet({
      itemList: itemList,
      itemColor: "#405f80",
      success: function (res) {
        wx.showModal({
          title: '用户将消息' + itemList[res.tapIndex],
        })
      }
    })


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})